package com.github.skystardust.lotteryex.lottery.item.imp.award;

import com.github.skystardust.lotteryex.lottery.item.AwardItem;
import lombok.EqualsAndHashCode;
import lombok.ToString;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;

import java.util.Map;
import java.util.UUID;

@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
public class AwardItemCommand extends AwardItem<String> {


    public AwardItemCommand(String awardItem) {
        super(awardItem);
    }

    public AwardItemCommand(UUID uuid, String awardItem) {
        super(uuid, awardItem);
    }

    public AwardItemCommand(Map<String, Object> stringObjectMap) {
        super(stringObjectMap);
        setAwardItem(((String) stringObjectMap.get("awardItem")));
    }

    @Override
    public void giveAward(Player player) {
        if (getAwardItem().startsWith("console:")) {
            String replace = getAwardItem().replace("console:", "");
            Bukkit.dispatchCommand(Bukkit.getConsoleSender(), replace);
        } else {
            Bukkit.dispatchCommand(player, getAwardItem());
        }
    }

}
